package com.br.servicos;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;



public class DBAdapter {

	// Database fields
		private SQLiteDatabase database;
		private MySQLiteHelper dbHelper;
		private String[] allColumns = { MySQLiteHelper.COLUMN_LOGIN, MySQLiteHelper.COLUMN_SENHA};

		public DBAdapter(Context context) {
			dbHelper = new MySQLiteHelper(context);
		}

		public void open() throws SQLException {
			database = dbHelper.getWritableDatabase();
		}

		public void close() {
			dbHelper.close();
		}
	
		public void criaLogin(String login, String senha) {
			
			String insere = "INSERT INTO login (login, senha) VALUES('"+login+"','"+senha+"')";
		    database.execSQL(insere);
		}
		
		public void deletaLogin() {

		    String delete = "DELETE FROM login";
		    database.execSQL(delete);
		    
		}

	
	    // Getting single contact
		public Comment getAllContacts() {
		    
		    Comment comment = new Comment();
		    
		    try{
		    //SQLiteDatabase db = this.getWritableDatabase();
		    Cursor cursor = database.query(MySQLiteHelper.TABLE_LOGIN, allColumns, null, null,null, null, null);
		    
		    if (cursor.moveToFirst()) {
		        do {
		            comment.setLogin(cursor.getString(0));
		            comment.setSenha(cursor.getString(1));
		        } while (cursor.moveToNext());
		    }
		    
		    }
		    catch (Exception e) {
			}
		    
		    return comment;
		}

}
